package com.xushu.learn_springboot_xushu.pojo;

import org.springframework.http.HttpStatus;

/**
 * @author: yu
 * @description: 封装一个通用的返回数据类型
 * @create: 2025/03/17 14:50
 */
public class ResponseMessage<T> {
    private Integer code;//200:成功 500：内部服务器错误 404：没有请求的资源
    private String message;//请求成功 请求失败
    private T data; //泛型

    public ResponseMessage(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

   /* public ResponseMessage() {

    }*/

   /* public static <T> ResponseMessage<T> success(T data){
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setCode(HttpStatus.OK.value());  //200
        responseMessage.setMessage("success");
        responseMessage.setData(data);
        return responseMessage;
    }*/

   // 接口请求成功
   public  static <T> ResponseMessage<T> success(T data){
       return new ResponseMessage(HttpStatus.OK.value(),"success!", data);
   }


    // 接口请求成功
    public  static <T> ResponseMessage<T> success(){
        return new ResponseMessage(HttpStatus.OK.value(),"success!", null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
